﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity;
using XSTDZ.ERP.Domain.Models;
using XSTDZ.ERP.Core.Extentions;

namespace XSTDZ.ERP.Domain.Repositories
{
    public class ERPContextInitailizer : DropCreateDatabaseIfModelChanges<ERPAppContextContainer>
    {
        protected override void Seed(ERPAppContextContainer context)
        {
            
        }
    }
     public class ERPInitailizer
     {
         ERPAppContextContainer context;
        public ERPInitailizer()
        {
            context = new ERPAppContextContainer();
        }
       public void initData()
       {
           MenuInit();
       }

       #region 数据初始化

       private void MenuInit()
       {

           #region 初始化菜单
           var defaultMenuIcon = "../Content/images/bullet_blue.png";

           var operations = new List<Operation> { 
             new Operation{ Id=Guid.NewGuid(), Code="LCYW", OperationName="老厂业务", Desc="老厂业务"},
             new Operation{ Id=Guid.NewGuid(), Code="XCYW", OperationName="新厂业务", Desc="新厂业务"},
             new Operation{ Id=Guid.NewGuid(), Code="CDYW", OperationName="成都业务", Desc="成都业务"},
             new Operation{ Id=Guid.NewGuid(), Code="SZYW", OperationName="深圳业务", Desc="深圳业务"},
             new Operation{ Id=Guid.NewGuid(), Code="XCCW", OperationName="新厂财务", Desc="新厂财务"},
             new Operation{ Id=Guid.NewGuid(), Code="CDCW", OperationName="成都财务", Desc="成都财务"},
             new Operation{ Id=Guid.NewGuid(), Code="SZCW", OperationName="深圳财务", Desc="深圳财务"},
             new Operation{ Id=Guid.NewGuid(), Code="JXSGL", OperationName="经销商管理", Desc="经销商管理"},
             new Operation{ Id=Guid.NewGuid(), Code="JCSJ", OperationName="基础数据", Desc="基础数据"},
             new Operation{ Id=Guid.NewGuid(), Code="XTGL", OperationName="系统管理", Desc="系统管理"}

           };
           operations.Each(o => o.ParentID = o.Id);
           operations[0].ChildrenOperations = new HashSet<Operation>{
                      new Operation{ Id=Guid.NewGuid(), Code="FHGL", OperationName="发货管理", Desc="发货管理", IconUrl=defaultMenuIcon, ParentID=operations[0].Id},
                      new Operation{ Id=Guid.NewGuid(), Code="THQR", OperationName="退货确认", Desc="退货确认", IconUrl=defaultMenuIcon, ParentID=operations[0].Id} 
                 };

           operations[1].ChildrenOperations = new HashSet<Operation>{
                      new Operation{ Id=Guid.NewGuid(), Code="FHGL", OperationName="发货管理", Desc="发货管理", IconUrl=defaultMenuIcon, ParentID=operations[1].Id},
                      new Operation{ Id=Guid.NewGuid(), Code="THQR", OperationName="退货确认", Desc="退货确认", IconUrl=defaultMenuIcon, ParentID=operations[1].Id} 
                 };


           operations[2].ChildrenOperations = new HashSet<Operation>{
                      new Operation{ Id=Guid.NewGuid(), Code="SHQR", OperationName="收货确认", Desc="收货确认", IconUrl=defaultMenuIcon, ParentID=operations[2].Id},
                      new Operation{ Id=Guid.NewGuid(), Code="RKGL", OperationName="入库管理", Desc="入库管理", IconUrl=defaultMenuIcon, ParentID=operations[2].Id},
                      new Operation{ Id=Guid.NewGuid(), Code="FHGL", OperationName="发货管理", Desc="发货管理", IconUrl=defaultMenuIcon, ParentID=operations[2].Id},
                      new Operation{ Id=Guid.NewGuid(), Code="THQR", OperationName="退货确认", Desc="退货确认", IconUrl=defaultMenuIcon, ParentID=operations[2].Id},
                      new Operation{ Id=Guid.NewGuid(), Code="XSGL", OperationName="销售管理", Desc="销售管理", IconUrl=defaultMenuIcon, ParentID=operations[2].Id},
                      new Operation{ Id=Guid.NewGuid(), Code="XSTHGL", OperationName="销售退货管理", Desc="销售退货管理", IconUrl=defaultMenuIcon, ParentID=operations[2].Id},
                      new Operation{ Id=Guid.NewGuid(), Code="THCLGL", OperationName="退货厂里管理", Desc="退货厂里管理", IconUrl=defaultMenuIcon, ParentID=operations[2].Id},
                      new Operation{ Id=Guid.NewGuid(), Code="PDGL", OperationName="盘点管理", Desc="盘点管理", IconUrl=defaultMenuIcon, ParentID=operations[2].Id},
                      new Operation{ Id=Guid.NewGuid(), Code="SYBG", OperationName="损溢报告", Desc="损溢报告", IconUrl=defaultMenuIcon, ParentID=operations[2].Id}
                 };


           operations[3].ChildrenOperations = new HashSet<Operation>{
                      new Operation{ Id=Guid.NewGuid(), Code="SHQR", OperationName="收货确认", Desc="收货确认", IconUrl=defaultMenuIcon, ParentID=operations[3].Id},
                      new Operation{ Id=Guid.NewGuid(), Code="RKGL", OperationName="入库管理", Desc="入库管理", IconUrl=defaultMenuIcon, ParentID=operations[3].Id},
                      new Operation{ Id=Guid.NewGuid(), Code="FHGL", OperationName="发货管理", Desc="发货管理", IconUrl=defaultMenuIcon, ParentID=operations[3].Id},
                      new Operation{ Id=Guid.NewGuid(), Code="XSGL", OperationName="销售管理", Desc="销售管理", IconUrl=defaultMenuIcon, ParentID=operations[3].Id},
                      new Operation{ Id=Guid.NewGuid(), Code="XSTHGL", OperationName="销售退货管理", Desc="销售退货管理", IconUrl=defaultMenuIcon, ParentID=operations[3].Id},
                      new Operation{ Id=Guid.NewGuid(), Code="THCDGL", OperationName="退货成都管理", Desc="退货成都管理", IconUrl=defaultMenuIcon, ParentID=operations[3].Id},
                      new Operation{ Id=Guid.NewGuid(), Code="PDGL", OperationName="盘点管理", Desc="盘点管理", IconUrl=defaultMenuIcon, ParentID=operations[3].Id},
                      new Operation{ Id=Guid.NewGuid(), Code="SYBG", OperationName="损溢报告", Desc="损溢报告", IconUrl=defaultMenuIcon, ParentID=operations[3].Id}
                 };

           operations[4].ChildrenOperations = new HashSet<Operation>{
                      new Operation{ Id=Guid.NewGuid(), Code="JJGL", OperationName="计件管理", Desc="计件管理", IconUrl=defaultMenuIcon, ParentID=operations[4].Id},
                      new Operation{ Id=Guid.NewGuid(), Code="JJGZJS", OperationName="计件工资计算", Desc="计件工资计算", IconUrl=defaultMenuIcon, ParentID=operations[4].Id}
                 };
           operations[5].ChildrenOperations = new HashSet<Operation>{
                      new Operation{ Id=Guid.NewGuid(), Code="ZDGL", OperationName="账单管理", Desc="账单管理", IconUrl=defaultMenuIcon, ParentID=operations[5].Id},
                      new Operation{ Id=Guid.NewGuid(), Code="SFKGL", OperationName="收付款管理", Desc="收付款管理", IconUrl=defaultMenuIcon, ParentID=operations[5].Id},
                      new Operation{ Id=Guid.NewGuid(), Code="RCCW", OperationName="日常财务", Desc="日常财务", IconUrl=defaultMenuIcon, ParentID=operations[5].Id}
                 };
           operations[6].ChildrenOperations = new HashSet<Operation>{
                      new Operation{ Id=Guid.NewGuid(), Code="ZDGL", OperationName="账单管理", Desc="账单管理", IconUrl=defaultMenuIcon, ParentID=operations[6].Id},
                      new Operation{ Id=Guid.NewGuid(), Code="SFKGL", OperationName="收付款管理", Desc="收付款管理", IconUrl=defaultMenuIcon, ParentID=operations[6].Id},
                      new Operation{ Id=Guid.NewGuid(), Code="RCCW", OperationName="日常财务", Desc="日常财务", IconUrl=defaultMenuIcon, ParentID=operations[6].Id}
                 };

           operations[7].ChildrenOperations = new HashSet<Operation>{
                      new Operation{ Id=Guid.NewGuid(), Code="JXSGL", OperationName="经销商管理", Desc="经销商管理", IconUrl=defaultMenuIcon, ParentID=operations[7].Id},
                      new Operation{ Id=Guid.NewGuid(), Code="LXRGL", OperationName="联系人管理", Desc="联系人管理", IconUrl=defaultMenuIcon, ParentID=operations[7].Id},
                      new Operation{ Id=Guid.NewGuid(), Code="DBGL", OperationName="调拨管理", Desc="调拨管理", IconUrl=defaultMenuIcon, ParentID=operations[7].Id}
                 };

           operations[8].ChildrenOperations = new HashSet<Operation>{
                      new Operation{ Id=Guid.NewGuid(), Code="KFGL", OperationName="库房维护", Desc="库房维护", IconUrl=defaultMenuIcon, ParentID=operations[8].Id},
                      new Operation{ Id=Guid.NewGuid(), Code="CPWH", OperationName="产品维护", Desc="产品维护", IconUrl=defaultMenuIcon, ParentID=operations[8].Id},
                      new Operation{ Id=Guid.NewGuid(), Code="MBXX", OperationName="码表信息", Desc="码表信息", IconUrl=defaultMenuIcon, ParentID=operations[8].Id}
                 };

           operations[9].ChildrenOperations = new HashSet<Operation>{
                      new Operation{ Id=Guid.NewGuid(), Code="SJBF", OperationName="数据备份", Desc="数据备份", IconUrl=defaultMenuIcon, ParentID=operations[9].Id},
                      new Operation{ Id=Guid.NewGuid(), Code="MMXG", OperationName="密码修改", Desc="密码修改", IconUrl=defaultMenuIcon, ParentID=operations[9].Id},
                      new Operation{ Id=Guid.NewGuid(), Code="JSGL", OperationName="结账管理", Desc="结账管理", IconUrl=defaultMenuIcon, ParentID=operations[9].Id}
                 };

           operations.Each(o => context.Operation.Add(o));
           context.SaveChanges();
           #endregion
       }

       //码表的初始化
       private void RefeInit()
       {
           IList<RefeType> refeTypes = new List<RefeType> {
             new RefeType{ Id=Guid.Parse("DFB6639D-93AA-4113-9729-0913414ACB01"), ModuleName="仓库类型", TypeName="仓库类型"},
             new RefeType{ Id=Guid.Parse("DC3E7361-96E5-4AEE-9A9E-6F67DA06C548"), ModuleName="性别", TypeName="性别"}
           };
           refeTypes[0].Refes = new HashSet<Refe> { 
             new Refe{ Id=Guid.NewGuid(), RefeCode="csck", RefeName="测试仓库", CreateTime=DateTime.Now, CreateID=refeTypes[0].Id, RefeTypeId=refeTypes[0].Id, Deleted=0}
           };
       }
       #endregion
     }
    
}
